<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/Product for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Product\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel,
	Product\Form\ProductForm,
	Product\Form\SearchForm,
	Product\Model\Entity\Product,
	Product\Model\Entity\Z_index,
	Zend\Db\Adapter\Adapter;
use Product\Model\ProductTable;

class ProductController extends AbstractActionController
{

	protected $productTable;
	
    public function indexAction()
    {
    	
    	$uri = $this->getRequest()->getUri();
    	$scheme = $uri->getScheme();
    	$host = $uri->getHost();
    	$base = sprintf('%s://%s', $scheme, $host);
		
/*		$form = new SearchForm(); 
        $form->get('submit')->setValue('Add');
		$request = $this->getRequest(); 

		if($request->isPost()) 
		{ 
			$product = new ProductTable(); 
			
			$formValidator = new Validator(); 
			{ 
				$form->setInputFilter($formValidator->getInputFilter()); 
				$form->setData($request->getPost()); 
			} 
			 
			if($form->isValid())
			{ 
				$product->search($form->getData());
				return $this->redirect()->toRoute('product');
			} 
				
		} */
    	
    	return new ViewModel(array(
            'zz_indexs' => $this->getProductTable()->fetchAll(),
		//	'form' => $form,
        ));
		echo 'Sembarang';
    }

	public function fooAction()
    {
        // This shows the :controller and :action parameters in default route
        // are working when you browse to /product/product/foo
        return array();
    }
	
	 public function createAction()
    {
		
    }
	
	 public function createcatalogAction(){
	 }
	 public function categoryAction(){
	 }
	 public function createcategoryAction(){
	 }
	 
	 public function cobaAction(){
		//echo "Brantas";
		
		$form = new ProductForm(); 
        $form->get('submit')->setValue('Save');
		$request = $this->getRequest(); 

		if($request->isPost()) 
		{ 
			$product = new Product(); 
			$form->setInputFilter($product->getInputFilter()); 
			$form->setData($request->getPost()); 
						 
			if($form->isValid())
			{ 
				echo 'valid';
				$product->exchangeArray($form->getData()); 
				$this->getProductTables()->saveProduct($product);
			}
			echo $product->getName();
			$testing = $form->getData();
			echo $testing['name'];
				
		}return array('form' => $form);
		
	}
	 
	public function getProductTable()
    {
        if (!$this->productTable) {
            $sm = $this->getServiceLocator();
            $this->productTable = $sm->get('Product\Model\ProductTable');
        }
        return $this->productTable;
    }
	
	public function getProductTables()
    {
        if (!$this->productTable) {
            $sm = $this->getServiceLocator();
            $this->productTable = $sm->get('Product\Model\ProductTables');
        }
        return $this->productTable;
    }
}
